#include "media/logic/MediaLogicGO.h"

MediaLogicGO::MediaLogicGO(QMap<QString, QMap<QString, QString>> &RGLRLSMAP,
                           QSqlDatabase *DB,
                           QMap<QString, QString> &QSSMAP)
                           :MediaLogicAC(RGLRLSMAP,
                                         DB,
                                         QSSMAP){
    QTimer::singleShot(150, this, &MediaLogicGO::mtpl_glbreserve_duty);
    diary("init successful", Diary::Debug)
}

void MediaLogicGO::mtpl_glbreserve_duty(){
    //#闪退原因，abstract_loader_procesend函数执行amend，查询数据，与该函数查询造成资源竞争
    QMap<QString, QList<QString>> SqlMediaInfo = definfc.SuperQuery(DATABASE, "media_datum");
    impact_ststr["anysql-name"] = SqlMediaInfo["mdrs_name"];
    impact_ststr["anysql-path"] = SqlMediaInfo["mdrs_path"];
    impact_ststr["anysql-lyric"] = SqlMediaInfo["mdrs_lyric"];
    impact_ststr["anysql-owner"] = SqlMediaInfo["owner"];
    impact_ststr["anysql-allpath"] = definfc.canonicalPath(SqlMediaInfo["mdrs_path"]);
    if (!isEnabled()) setEnabled(true);
    diary("get reserve duty", Diary::Debug)
}

void MediaLogicGO::mtpl_resource_initloader(){
    if (impact_ststr["reserve-duty-name"].isEmpty())
    {
        if ((*__RLMAP__)["MSC"]["CurrentSwitchOverType"].toInt())
        {
            mtpl_viewdata_amend(NT::CUT_VIDEO_TYPE);
        }
        else
        {
            mtpl_viewdata_amend(NT::CUT_MUSIC_TYPE);
        }
    }
    diary("init resource loader", Diary::Debug)
}

void MediaLogicGO::mtpl_viewdata_amend(NT::CUT_MEDIA_TYPE Type, QString fillQuery){
    //隐藏状态由开关判断是最直观的，可避免按钮点击和列表双击，medialist索引变更的遗漏点和延迟问题
    impact_str["mdrs-sql-filler"] = fillQuery;
    impact_identify["mdrs-table-type"] = Type;
    BoilPool->run(ThreadPoint::MULTI_AMEND);
    diary("begin amend", Diary::Debug);
}

void MediaLogicGO::mtpl_resource_loadend(){
    RTP_addHint->doconfigur_formattext(QString::number(RT_mediaTabWidget->rowCount()));
    RT_mediaTabWidget->suspendUpdate();
    impact_swtc["tab-column-specing-adjusted"] = false;
    diary("hstry item show", Diary::Debug);
}

void MediaLogicGO::mtpl_mousev_impactpre(){
    /*将产生一个双击事件和两个单击事件，顺序为单击 - 双击 - 单击, 添加定时任务判断是否双击,
    当前处理逻辑为收集点击次数，定时任务开启时判断点击次数，大于3次时(单击 ，双击 ，单击)
    认定该操作为双击，小于则运行常规点击逻辑*/
    if (MT_MediaPlayer->hasVideo()){
        impact_int["mdrs-video-index"] += 1;
        if (!MULTI_DLPL_QTIER.isActive())
        {
            MULTI_DLPL_QTIER.start();
        }
    } else mtpl_standar_impactpre(true);

}

void MediaLogicGO::mtpl_standar_impactpre(bool onlybrave){
    bool isbeplay = false;
    QString cover = impact_ststr["reserve-duty-cover"][impact_int["mdrs-indexof"]];
    QString suffix = impact_ststr["reserve-duty-suffix"][impact_int["mdrs-indexof"]];
    if (onlybrave)
    {
        if (impact_swtc["mdplr-current-state"])
        {
            MT_MediaPlayer->pause();
            MT_mediastat->setExtraPree(PlayerDecide::DecideFalse);
            RT_videoWidget->mtpl_mediastat->setExtraPree(PlayerDecide::DecideFalse);
        } else {
            mtpl_resource_loader(impact_int["mdrs-indexof"]);
            MT_tracksCover->doconfigur_pixmap(cover);
            MT_mediastat->setExtraPree(PlayerDecide::DecideTrue);
            RT_videoWidget->mtpl_mediastat->setExtraPree(PlayerDecide::DecideTrue);
            isbeplay = true;
        }
    } else {
        if (impact_swtc["mdplr-current-state"])
        {
            MT_tracksCover->doconfigur_pixmap(cover);
            MT_mediastat->setExtraPree(PlayerDecide::DecideTrue);
            RT_videoWidget->mtpl_mediastat->setExtraPree(PlayerDecide::DecideTrue);
            isbeplay = true;
        } else {
            MT_mediastat->setExtraPree(PlayerDecide::DecideFalse);
            RT_videoWidget->mtpl_mediastat->setExtraPree(PlayerDecide::DecideFalse);
        }
        mtpl_resource_loader(impact_int["mdrs-indexof"]);
    }
    if (isbeplay)
    {
        Query->prepare("UPDATE media_datum SET nrply_time=? WHERE mdrs_path=?;");
        Query->bindValue(0, QDateTime().currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
        Query->bindValue(1, impact_ststr["reserve-duty-path"][impact_int["mdrs-indexof"]]);
        Query->exec();
        impact_swtc["mdplr-current-state"] = true;

        if (impact_ststr["fm-video"].contains(suffix) && !RT_videoWidget->isVisible())
        {
            RT_videoWidget->setMinimumSize(size() - QSize(60, 60));
            RT_videoWidget->setVisible(true);
        }
        else
        {
            mtpl_musiclrc_touch();
        }
        MT_MediaPlayer->play();;
    }
    else
    {
        impact_swtc["mdplr-current-state"] = false;
    }
}

void MediaLogicGO::mtpl_musiclrc_touch(){
    QList<QVariant> receiveli;
    impact_thread[ThreadPoint::MULTI_MDLYCDATE] = NT::THREAD_RECOVER;
    QString multi_lyric = impact_ststr["reserve-duty-lyric"][impact_int["mdrs-indexof"]];
    QString multi_names = impact_ststr["reserve-duty-name"][impact_int["mdrs-indexof"]];
    QString multi_artist = impact_ststr["reserve-duty-artist"][impact_int["mdrs-indexof"]];
    if (multi_lyric.isEmpty())
    {
        QString address = REGISTER_BASEINFO_163MSC_ADDRESS.arg(multi_names + multi_artist, QString::number(20));
        QString key = QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate);
        SCROPED_RESDOWN_SINGEXEC(address, NULL, NULL, FLAG_RESHOURCE_GET, key, receiveli, impact_thread)
        QThread::msleep(100);
        int global_index = 0;
        while (global_index < receiveli.size())
        {
            QVariant receiveinfo = receiveli[global_index];
            if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_TERMINATED)
            {
                break;
            }
            else if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_PAUSE)
            {
                while (true)
                {
                    if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_PAUSE)
                    {
                        QThread::msleep(15);
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else
            {
                QJsonDocument infodocument = ResdownLoad::jsparser(receiveinfo.toByteArray());
                ResdownLoad::mdpldata infostruct = ResdownLoad::jsparserTostruct(infodocument, STRUCTYPE_MDRS);
                QStringList parseridli;
                ResdownLoad::g_jsonkey({"artists"}, "name", parseridli, infodocument);
                QStringList ideaidli = parseridli.filter(multi_artist);
                if (ideaidli.isEmpty())
                {
                    ideaidli << infostruct.MDRS_ID;
                }
                else
                {
                    for(int indexof = 0; indexof < ideaidli.length(); indexof++)
                    {
                        QStringList infos = parseridli[indexof].split("-");
                        ideaidli.replace(indexof, infos.last());
                    }
                }
                qDebug() << ideaidli << parseridli;
//                foreach (QString id, parseridli)
//                {
//                    QVariant lycdata;
//                    QString address = REGISTER_BASEINFO_163MSCLYC_ADDRESS.arg(id);
//                    SCROPED_RESDOWN_SINGEXEC(address, NULL, NULL, FLAG_RESHOURCE_GET, key, lycdata, impact_thread)
//                    if (!lycdata.isNull())
//                    {
//                        QJsonDocument lyric_document = ResdownLoad::jsparser(lycdata.toByteArray());
//                        qDebug() << lycdata.toString() << lyric_document["lrc"];
//                        break;
//                    }
//                }
            }
            global_index++;
        }
    }

}

void MediaLogicGO::mtpl_resource_loader(int MultiIndexOf){
    RT_lyricLabel->clear();
    NT::CUT_MEDIA_TYPE TabSwitchType = impact_identify["mdrs-table-type"];
    impact_int["mdrs-indexof"] = MultiIndexOf;
    TABRSASSERT
    {
        QString media_name = impact_ststr["reserve-duty-name"][MultiIndexOf];
        QString media_path = impact_ststr["reserve-duty-path"][MultiIndexOf];
        QUrl media_content = QUrl(media_path);
        if (MT_MediaPlayer->source() != media_content && !media_path.isEmpty())
        {
            MT_MediaPlayer->setSource(media_content);
            MT_tracksEcho->setText(media_name);
            RT_videoWidget->mtpl_tracksname->setText(media_name);
            RT_lyricLabel->setText("开始匹配歌词");
            if (TabSwitchType == NT::CUT_MUSIC_TYPE)
            {

            }
        }
    }
    else
    {
        diary("list index over range", Diary::Debug)
    }
}

void MediaLogicGO::mtpl_otherness_assert(QList<int> willbedel){
    diary("compute defferential data of the table", Diary::Warning)
    RT_mediaTabWidget->del(willbedel, false);
    RT_mediaTabWidget->descReset();
    impact_swtc["otherness-finish"] = true;

}

void MediaLogicGO::mtpl_mddsp_core(QMediaPlayer::MediaStatus mediastat, PlayerDFswapKey swapkey){
    int rowcount =impact_ststr["reserve-duty-name"].size() - 1;
    if (mediastat == QMediaPlayer::EndOfMedia){
        RT_lyricLabel->clear();
        if (swapkey == PlayerDFswapKey::UnSwapKey){
            if (mediaModeType == MEDIAPLMD::PLMD_LOOP){
                if (impact_int["mdrs-indexof"] == rowcount){
                    impact_int["mdrs-indexof"] = 0;
                } else {
                    impact_int["mdrs-indexof"] += 1;
                }
                emit sg_standar_amend(false);
            } else if (mediaModeType == MEDIAPLMD::PLMD_RANDOM){
                impact_int["mdrs-indexof"] = definfc.Getrandom(0, rowcount);
                mtpl_resource_loader(impact_int["mdrs-indexof"]);
                MT_MediaPlayer->play();
            } else if (mediaModeType == MEDIAPLMD::PLMD_DESC){
                if (impact_int["mdrs-indexof"] == rowcount){
                        MT_MediaPlayer->stop();
                } else {
                    impact_int["mdrs-indexof"] += 1;
                    emit sg_standar_amend(false);
                }
            } else if (mediaModeType == MEDIAPLMD::PLMD_ONCE){
                MT_MediaPlayer->stop();

            } else if (mediaModeType == MEDIAPLMD::PLMD_ONCELOOP){
                emit sg_standar_amend(false);
            }
        } else {
            if (mediaModeType == MEDIAPLMD::PLMD_RANDOM){
                impact_int["mdrs-indexof"] = definfc.Getrandom(0, rowcount);
            } else {
                if (swapkey == PlayerDFswapKey::NextMedia) {
                    if (impact_int["mdrs-indexof"] == rowcount) {
                        impact_int["mdrs-indexof"] = 0;
                    } else {
                        impact_int["mdrs-indexof"] += 1;
                    }
                } else {
                    if (impact_int["mdrs-indexof"] == 0) {
                        impact_int["mdrs-indexof"] = rowcount;
                    } else {
                        impact_int["mdrs-indexof"] -= 1;
                    }
                }
            }
            emit sg_standar_amend(false);
        }
        TABRSASSERT RT_mediaTabWidget->selectRow(impact_int["mdrs-indexof"]);
    }
}

void MediaLogicGO::mtpl_resource_removend(){
    QList<int> rows = RT_mediaTabWidget->prossRows(true);
    if (RT_mediaTabWidget->del(rows))
    {
        foreach(int index, rows)
        {
           impact_ststr["reserve-duty-name"].removeAt(index);
           impact_ststr["reserve-duty-artist"].removeAt(index);
           impact_ststr["reserve-duty-suffix"].removeAt(index);
           impact_ststr["reserve-duty-bitrate"].removeAt(index);
           impact_ststr["reserve-duty-size"].removeAt(index);
           impact_ststr["reserve-duty-duration"].removeAt(index);
        }
        RT_mediaTabWidget->descReset();
    }
    RT_mediaTabWidget->suspendUpdate();
}

void MediaLogicGO::mtpl_resdownload_ds(QVariant ar1, QVariant ar2, ulong flag){
    if (flag == DOWN_PROCESS)
    {
        qint64 c = ar1.value<qint64>();
        qint64 t = ar2.value<qint64>();
        if (c && t)
        {
            abstract_loader_processing(((double)c / t) * 100, "K_LiteCode Dowloading...");
            LD_cheduhint->doconfigur_text("current: " + QString::number(c) + " total: " + QString::number(t));

        }
    }

    else if (flag == DOWN_PROCESSSTAT)
    {
        if(ar1.toBool())
        {
            RT_sliderShow->backview();
        }
        else
        {
            LD_cheduleBar->setWingsgraph(true);
        }
    }
}

void MediaLogicGO::mtpl_resdownload_envc(QPushButton *buttom){
    if (buttom->text() == "sure")
    {
        QTimer::singleShot(1000, this, [=](){
        QString klitecodepath = (*__RLMAP__)["VSTADDRE"]["suportplugGetAddres"];
        QString klitecodename = klitecodepath.split(QRegularExpression("[\\\\|/]")).last();
        QString officpath = (*__RLMAP__)["PATH"]["SYSFD"] + "/" + "K-LITECODE"; SCROPED_DIR_MAKE(officpath, false)
        QString klitecodesavepath = officpath + "/" + klitecodename;
        QString mutexInstaller = "start-process %1 -ArgumentList \'/DIR=%2 /VERYSILENT\' -NoNewWindow -wait";
        setProperty("klitecodepath", klitecodepath);
        setProperty("klitecodesavepath", klitecodesavepath);
        setProperty("mutexInstaller", mutexInstaller.arg(klitecodesavepath, officpath));
        QMap<QString, QString> ifmap = Request.getrawHeader(klitecodepath);
        QFile f(klitecodesavepath);
        if (!f.exists() || (f.exists() && ifmap["Content-Length"].toInt() != f.size()))
        {
            QString tem_klitecodepath = property("klitecodepath").toString();
            QString tem_klitecodesavepath = property("klitecodesavepath").toString();
            diary("set request info: " + tem_klitecodepath + "+" + tem_klitecodesavepath, Diary::Debug)
            Request.appendInfo(tem_klitecodepath, "", tem_klitecodesavepath, FLAG_RESHOURCE_GETE);
            Request.start();
            diary("k-lite-code downloading", Diary::Debug)
            connect(&Request, &ResdownLoad::finished, this, [&]()
            {
                QString commandprocess = property("mutexInstaller").toString();
                bool installer = definfc.startProcess(commandprocess);
                QString regedit_klite_info = definfc.regeditVist(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\KLCodecPack", "installdir").toString();
                diary(commandprocess + " exec " + regedit_klite_info, Diary::Debug)
                if (installer && QFile(regedit_klite_info.trimmed()).exists())
                {
                    MessageBoxQ *_msg_ = new MessageBoxQ(this, {"ok"}, MessageBoxQ::MSG_Error, "环境搭建", "环境搭建成功");
                    connect(_msg_, &MessageBoxQ::checkEvent, this, [&](){mtpl_resource_initloader();});
                }
                else
                {
                    MessageBoxQ *_msg_ = new MessageBoxQ(this, {"ok"}, MessageBoxQ::MSG_Error, "环境搭建", "环境搭建失败，请检查环境地址或网络");
                    connect(_msg_, &MessageBoxQ::checkEvent, this, [&](){mtpl_resource_initloader();});
                }
            });
        }
        else
        {
            diary("k-lite-code is exists, installing...", Diary::Debug)
            bool installer = definfc.startProcess(property("mutexInstaller").toString());
            QString regedit_klite_info = definfc.regeditVist(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\KLCodecPack", "installdir").toString();
            if (installer && QFile(regedit_klite_info.trimmed()).exists())
            {
                MessageBoxQ *_msg_ = new MessageBoxQ(this, {"ok"}, MessageBoxQ::MSG_Error, "环境搭建", "环境搭建成功");
                connect(_msg_, &MessageBoxQ::checkEvent, this, [&](){mtpl_resource_initloader();});
            }
            else
            {
                MessageBoxQ *_msg_ = new MessageBoxQ(this, {"ok"}, MessageBoxQ::MSG_Error, "环境搭建", "环境搭建失败，请检查环境地址或网络");
                connect(_msg_, &MessageBoxQ::checkEvent, this, [&](){mtpl_resource_initloader();});
            }
        }
        });
    }
    else
    {
        mtpl_resource_initloader();
    }

}

void MediaLogicGO::mtpl_dall_play(){
}

void MediaLogicGO::basic_configration_init(){
    diary("configration init", Diary::Debug)
    /* windown geometry-size set*/
    QString rules_width = (*__RLMAP__)["MSC"]["WindownGeometryW"];
    QString rules_height = (*__RLMAP__)["MSC"]["WindownGeometryH"];
    bool check = (!rules_width.isEmpty() && !rules_height.isEmpty() && definfc.isInt(rules_width) && definfc.isInt(rules_height));
    check ? resize(rules_width.toUInt(), rules_height.toUInt()) : resize(1020, 630);
    setVisible(true);
    /* K-liteCode Env Check*/
    QString regedit_klite_info = definfc.regeditVist(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\KLCodecPack", "installdir").toString();
    if (!regedit_klite_info.isEmpty() && QFile(regedit_klite_info.trimmed()).exists())
    {
        mtpl_resource_initloader(); // first time must running
        diary("k-lite-code assert true", Diary::Debug)
    }
    else
    {
        MessageBoxQ *message = new MessageBoxQ(this, {"sure", "ignore"}, MessageBoxQ::MSG_Error, "环境错误", "检测到本地没有解码环境，将自动搭建环境");
        connect(message, &MessageBoxQ::checkEvent, this, &MediaLogicGO::mtpl_resdownload_envc);
    }
    /* path box default folder check */
    QString CommonlyFolder = (*__RLMAP__)["MSC"]["CommonlyFolder"];
    QFileInfo commonlyInfo = QFileInfo(CommonlyFolder);
    if (QFile(CommonlyFolder).exists())
    {
        if (commonlyInfo.isDir()){
            impact_str["mdrs-follow-directory"] = CommonlyFolder;
        } else {
            impact_str["mdrs-follow-directory"] = commonlyInfo.filePath();
        }
    }
    else
    {
        if (CommonlyFolder.toLower() == "follow")
        {
            impact_str["mdrs-follow-directory"] = CommonlyFolder;
        }
        else
        {
            impact_str["mdrs-follow-directory"] = "./";
        }
    }
    LF_localMeidaLabel->doconfigur_lock();
}

void MediaLogicGO::mtpl_backcover_update(){
    QList<QVariant> requestli;
    QList<QVariant> receiveli;
    QList<int> indexli;
    impact_thread[ThreadPoint::MULTI_MDCVUPDATE] = NT::THREAD_RECOVER;
    QList<QString> multi_covers = impact_ststr["reserve-duty-cover"];
    QList<QString> multi_names = impact_ststr["reserve-duty-name"];
    for(int index=0; index < multi_covers.length(); index++)
    {
        if (!Extend::pcheck(multi_covers[index]))
        {
            QString address = REGISTER_BASEINFO_163MSC_ADDRESS.arg(multi_names[index], QString::number(2));
            requestli.append(address);
            indexli.append(index);
         }
    }
    diary("media info count: " + QString::number(requestli.length()), Diary::Debug)
    QString key = QDateTime::currentDateTime().toString(Qt::DateFormat::TextDate);
    SCROPED_RESDOWN_ROPEEXEC(requestli, NULL, NULL, FLAG_RESHOURCE_GET, key, receiveli, impact_thread)
    QThread::msleep(100);
    int count = 0;
    diary4("request count: ", QString::number(requestli.size()), " receive info count: ", QString::number(receiveli.size()), Diary::Debug)
    QString defualtCover = ":/PIXMAP/bench/cover.jpg";
    int global_index = 0;
    while (global_index < receiveli.size())
    {
        QVariant receiveinfo = receiveli[global_index];
        if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_TERMINATED)
        {
            break;
        }
        else if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_PAUSE)
        {
            while (true)
            {
                if (impact_thread[ThreadPoint::MULTI_MDCVUPDATE] == NT::THREAD_PAUSE)
                {
                    QThread::msleep(15);
                    continue;
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
            QJsonDocument infodocument = ResdownLoad::jsparser(receiveinfo.toByteArray());
            ResdownLoad::mdpldata infostruct = ResdownLoad::jsparserTostruct(infodocument, STRUCTYPE_MDRS);
            int indexE = indexli[count];
            QString mdrs_name = multi_names[indexE];
            QStringList sqlsavepaths;
            if (!infostruct.MDRS_ID.isEmpty())
            {
                QList<QString> songsinfo = infostruct.get(infostruct.MDRS_ID.size() - 1);
                QVariant pixVariant;
                QString savepath = "";
                QString simplename = songsinfo[1] + "-" + songsinfo[2];
                if (songsinfo.size() >= 4)
                {
                    QString suffix = songsinfo[3].split(".").last();
                    QString sqlpath = impact_ststr["reserve-duty-path"][indexE];
                    QString _savepath;
                    if (QRegularExpression((*__RLMAP__)["REGEXP"]["HyperLinkExtract"]).match(sqlpath).hasMatch())
                    {
                        _savepath = (*__RLMAP__)["PATH"]["MSPATH"];
                    }
                    else
                    {
                        _savepath = QFileInfo(impact_ststr["reserve-duty-path"][indexE]).canonicalPath();
                    }
                    savepath = _savepath + "/" + simplename + "." + suffix;
                    if (QFile(savepath).exists())
                    {
                        sqlsavepaths.append(savepath);
                        impact_ststr["reserve-duty-cover"][indexE] = savepath;
                    }
                    else
                    {
                        QList<QVariant> coverli;
                        diary(REGISTER_INFODETAIL_163MSC_ADDRESS.arg(songsinfo[0]), Diary::Debug)
                        SCROPED_RESDOWN_SINGEXEC(REGISTER_INFODETAIL_163MSC_ADDRESS.arg(songsinfo[0]), NULL, NULL, FLAG_RESHOURCE_GET, key, coverli, impact_thread)
                        foreach(QVariant cover, coverli)
                        {
                            QJsonDocument coverdocument = ResdownLoad::jsparser(cover.toByteArray());
                            if (coverdocument["songs"].type() == QJsonValue::Array && coverdocument["songs"].toArray().size() >= 1)
                            {
                                QJsonObject album = coverdocument["songs"].toArray()[0].toObject();
                                QJsonValue album_pic = album["album"].toObject()["picUrl"];
                                songsinfo[3] = album_pic.toString();
                            }
                            SCROPED_RESDOWN_SINGEXEC(songsinfo[3], NULL, savepath, FLAG_RESHOURCE_GET, key, pixVariant, impact_thread)
                            diary2("cover get success: ", savepath, Diary::Debug);
                        }
                        if (pixVariant.isNull())
                        {
                            diary(simplename + " ->resource not find", Diary::Debug);
                            sqlsavepaths.append(defualtCover);
                            impact_ststr["reserve-duty-cover"][indexE] = defualtCover;
                        }
                        else
                        {
                            QPixmap pixmap;
                            if (pixmap.loadFromData(pixVariant.toByteArray()))
                            {
                                diary(simplename + " ->pixmap load sucess", Diary::Debug);
                                sqlsavepaths.append(savepath);
                                impact_ststr["reserve-duty-cover"][indexE] = savepath;
                            }
                            else
                            {
                                diary(simplename + " ->pixmap load fail", Diary::Debug)
                                sqlsavepaths.append(defualtCover);
                                impact_ststr["reserve-duty-cover"][indexE] = defualtCover;
                                continue;
                            }
                        }
                    }
                }
            }
            else
            {
                sqlsavepaths.append(defualtCover);
                impact_ststr["reserve-duty-cover"][indexE] = defualtCover;
            }
            QString coveradd_sqlchar = QString("UPDATE media_datum SET mdrs_cover='%1' WHERE mdrs_name='%2';").arg(sqlsavepaths.join("&&").remove(QRegularExpression("['\"]")), mdrs_name);
            bool sqlexec = Query->exec(coveradd_sqlchar);
            QString sqlerror = Query->lastError().text();
            if (sqlerror.simplified().isEmpty())
            {
                diary4("media_datum cover update stat: ", QString::number(sqlexec) ," for object: ", mdrs_name, Diary::Debug);
            }
            else
            {
                diary("media_datum cover update stat: " + QString::number(sqlexec) + " lamsg: " + sqlerror, Diary::Debug);
            }
            count++;
            QThread::msleep(5);
        }
        global_index++;
    }
    diary("media cover load finished", Diary::Success);
    impact_thread[ThreadPoint::MULTI_MDCVUPDATE] = NT::THREAD_IDLEABOUT;
    RT_mediaTabWidget->suspendUpdate();
}
